# -*- coding: utf-8 -*-
#coding=utf8

class HttpHelper(object):
	"""docstring for HttpHelper"""
	
	import httplib,urllib

	
	def Get(url):
		httpClient = None

		try:
		    httpClient = httplib.HTTPConnection('www.etlinking.com', 80, timeout=30)
		    httpClient.request('GET', '/')

		    #response是HTTPResponse对象
		    response = httpClient.getresponse()
		    
		    return response.read()
		except Exception, e:
		    raise e
		finally:
		    if httpClient:
		        httpClient.close()
	

	def Post(url,params):
		httpClient = None
		try:
		    #params = urllib.urlencode({'email': 'app@test.com', 'password': '123'})
		    headers = {"Content-type": "application/json"
		                , "Accept": "text/plain"}

		    httpClient = httplib.HTTPConnection("www.etlinking.com", 80, timeout=30)
		    httpClient.request("POST", "/app/login", params, headers)

		    response = httpClient.getresponse()
		    
		    print response.read()
		    print response.getheaders() #获取头信息
		except Exception, e:
		    print e
		finally:
		    if httpClient:
		        httpClient.close()